/*
 * Purchase.java
 *
 * Created on 13 novembre 2007, 14:13
 */
package com.reimscopie;

import java.util.* ;


/**
 * The class of a purchase.
 *
 * <p>Combines a product and a quantity.
 */
public class Purchase extends Value {
  
  // the product to purchase
  private Product product ;
  
  // the quantity of the purchased product 
  private int quantity ;
  
  // TODO: OPTIONS D'ACHAT
  

  /**
   * Create a new <code>Purchase</code> instance with all attributes. This
   * object has no image in the database.
   *
   * @param product The product to purchase.
   * @param quantity The quantity of the purchased product 
   */
  public Purchase(Product product,int quantity) {
    
    super() ;
    
    this.product  = product ;
    this.quantity = quantity ;
    
  }
  
  
  /**
   * Create a new <code>Purchase</code> instance with an image in the database.
   *
   * @param id The purshase id in the database.
   * @param product The product to purchase.
   * @param quantity The quantity of the purchased product.
   */
  public Purchase(long id,Product product,int quantity) {
    
    super(id) ;
    
    this.product  = product ;
    this.quantity = quantity ;
    
  }
  
  
  /**
   * Return the product of this purchase.
   *
   * @return The product.
   */
  public Product getProduct() {
    return product ;
  }
  
  
  /**
   * Return the quantity of the purchased product.
   *
   * @return the quantity of the purchased product.
   */
  public int getQuantity() {
    return quantity ;
  }
  
  
  /**
   * Return the total cost of this purchase.
   *
   * @return The purchase cost.
   */
  public float getTotalCost() {
    
    float cost = product.getTotalCost() ;
    
    cost *= quantity ;
    
    return cost ;
  }
  
  
  /**
   * Create a new map with all attributes of this value.
   *
   * @return A string-string map with the named attributes.
   */
  @Override
  public Map<String,String> toMap() {
    
    Map<String,String> map = new LinkedHashMap<String,String>() ;
    
    map.put("quantity",String.valueOf(quantity)) ;
    map.put("product",product.toString()) ;
    
    return map ;
  }
  
}
